package volcengine

import (
	request "gitee.com/changeden/volcengine-livesaas-request-go"
	"gitee.com/changeden/volcengine-livesaas-sdk-go/api"
	"log"
	"time"
)

const (
	Version = "0.0.4"
)

var (
	client *request.Client
)

type Instance struct {
	AccessKeyID     string
	SecretAccessKey string
	Region          string
	// 选填
	Timeout time.Duration
	Logger  *log.Logger

	version string
}

func (instance *Instance) getClient() *request.Client {
	if client == nil {
		client = &request.Client{
			Host:            "open.bytedanceapi.com",
			Protocol:        request.Https,
			AccessKeyID:     instance.AccessKeyID,
			SecretAccessKey: instance.SecretAccessKey,
			Region:          instance.Region,
			Service:         "livesaas",
			Timeout:         instance.Timeout,
			Logger:          instance.Logger,
		}
	}
	return client
}

func (instance *Instance) SetVersion(version string) *Instance {
	instance.version = version
	return instance
}

func (instance *Instance) getApiInstance() *api.Instance {
	return api.GetInstance(instance.getClient(), instance.version)
}

// 创建直播活动
func (instance *Instance) CreateActivity(data *api.CreateActivityRequest) (*api.CreateActivityResponse, error) {
	return instance.getApiInstance().CreateActivity(data)
}

// 删除直播活动 预留
//func (instance *Instance) DeleteActivity(data *api.DeleteActivityRequest) (*api.DeleteActivityResponse, error) {
//	return instance.getApiInstance().DeleteActivity(data)
//}

// 变更直播间状态
func (instance *Instance) UpdateActivityStatus(data *api.UpdateActivityStatusRequest) (*api.NoResultResponse, error) {
	return instance.getApiInstance().UpdateActivityStatus(data)
}

// 开始/关闭拉流
func (instance *Instance) UpdatePullToPush(data *api.UpdatePullToPushRequest) (*api.NoResultResponse, error) {
	return instance.getApiInstance().UpdatePullToPush(data)
}

// 获取直播基础信息
func (instance *Instance) GetActivity(data *api.GetActivityRequest) (*api.GetActivityResponse, error) {
	return instance.getApiInstance().GetActivity(data)
}

// 获取直播流信息
func (instance *Instance) GetStreams(data *api.GetStreamsRequest) (*api.GetStreamsResponse, error) {
	return instance.getApiInstance().GetStreams(data)
}

// 配置直播页面基础信息
func (instance *Instance) UpdateActivityBasicConfig(data *api.UpdateActivityBasicConfigRequest) (*api.NoResultResponse, error) {
	return instance.getApiInstance().UpdateActivityBasicConfig(data)
}

// 获取直播页面基础信息
func (instance *Instance) GetActivityBasicConfig(data *api.GetActivityBasicConfigRequest) (*api.GetActivityBasicConfigResponse, error) {
	return instance.getApiInstance().GetActivityBasicConfig(data)
}

// 获取直播活动列表信息
func (instance *Instance) ListActivity(data *api.ListActivityRequest) (*api.ListActivityResponse, error) {
	return instance.getApiInstance().ListActivity(data)
}

// 回放上传
func (instance *Instance) UploadReplay(data *api.UploadReplayRequest) (*api.NoResultResponse, error) {
	// TODO Bug
	return instance.getApiInstance().UploadReplay(data)
}

// 上架/下架/删除回放
func (instance *Instance) UpdateMediaOnlineStatus(data *api.UpdateMediaOnlineStatusRequest) (*api.NoResultResponse, error) {
	return instance.getApiInstance().UpdateMediaOnlineStatus(data)
}

// 获取回放文件列表
func (instance *Instance) ListMedias(data *api.ListMediasRequest) (*api.ListMediasResponse, error) {
	return instance.getApiInstance().ListMedias(data)
}

// 直播基础数据信息
func (instance *Instance) GetPageWatchData(data *api.GetPageWatchDataRequest) (*api.GetPageWatchDataResponse, error) {
	return instance.getApiInstance().GetPageWatchData(data)
}

// 营销数据信息
func (instance *Instance) GetAdvertisementData(data *api.GetAdvertisementDataRequest) (*api.GetAdvertisementDataResponse, error) {
	return instance.getApiInstance().GetAdvertisementData(data)
}

// 观众行为数据信息
func (instance *Instance) ListUserBehaviorData(data *api.ListUserBehaviorDataRequest) (*api.ListUserBehaviorDataResponse, error) {
	return instance.getApiInstance().ListUserBehaviorData(data)
}

// 问卷数据信息
func (instance *Instance) ListQuestionnaireAnswerData(data *api.ListQuestionnaireAnswerDataRequest) (*api.ListQuestionnaireAnswerDataResponse, error) {
	return instance.getApiInstance().ListQuestionnaireAnswerData(data)
}

// 问卷列表信息
func (instance *Instance) ListQuestionnaireData(data *api.ListQuestionnaireDataRequest) (*api.ListQuestionnaireDataResponse, error) {
	return instance.getApiInstance().ListQuestionnaireData(data)
}

// 获取实时在线人数
func (instance *Instance) GetRealTimeOnlineNumber(data *api.GetRealTimeOnlineNumberRequest) (*api.GetRealTimeOnlineNumberResponse, error) {
	return instance.getApiInstance().GetRealTimeOnlineNumber(data)
}

// 主持人发言
func (instance *Instance) PresenterChat(data *api.PresenterChatRequest) (*api.PresenterChatResponse, error) {
	return instance.getApiInstance().PresenterChat(data)
}

// 获取直播间评论
func (instance *Instance) PollingChat(data *api.PollingChatRequest) (*api.PollingChatResponse, error) {
	return instance.getApiInstance().PollingChat(data)
}

// 获取直播间热门评论
func (instance *Instance) GetHotChat(data *api.GetHotChatRequest) (*api.GetHotChatResponse, error) {
	return instance.getApiInstance().GetHotChat(data)
}

// 获取直播间置顶评论
func (instance *Instance) GetTopChat(data *api.GetTopChatRequest) (*api.GetTopChatResponse, error) {
	return instance.getApiInstance().GetTopChat(data)
}

// 删除直播间评论
func (instance *Instance) DeleteChat(data *api.DeleteChatRequest) (*api.DeleteChatResponse, error) {
	return instance.getApiInstance().DeleteChat(data)
}

// 评论点赞
func (instance *Instance) LikeChat(data *api.LikeChatRequest) (*api.LikeChatResponse, error) {
	return instance.getApiInstance().LikeChat(data)
}

// 评论置顶
func (instance *Instance) TopChat(data *api.TopChatRequest) (*api.TopChatResponse, error) {
	return instance.getApiInstance().TopChat(data)
}

// 清空直播间评论
func (instance *Instance) EmptyChat(data *api.EmptyChatRequest) (*api.EmptyChatResponse, error) {
	return instance.getApiInstance().EmptyChat(data)
}

// 发送图文直播
func (instance *Instance) SendGraphicMessage(data *api.SendGraphicMessageRequest) (*api.SendGraphicMessageResponse, error) {
	return instance.getApiInstance().SendGraphicMessage(data)
}

// 删除图文直播
func (instance *Instance) DeleteGraphicMessage(data *api.DeleteGraphicMessageRequest) (*api.DeleteGraphicMessageResponse, error) {
	return instance.getApiInstance().DeleteGraphicMessage(data)
}

// 拉取直播间图文直播
func (instance *Instance) PollingGraphicMessage(data *api.PollingGraphicMessageRequest) (*api.PollingGraphicMessageResponse, error) {
	return instance.getApiInstance().PollingGraphicMessage(data)
}

// 更改直播间评论先审后发状态
func (instance *Instance) UpdateChatReviewStatus(data *api.UpdateChatReviewStatusRequest) (*api.UpdateChatReviewStatusResponse, error) {
	return instance.getApiInstance().UpdateChatReviewStatus(data)
}

// 评论过审
func (instance *Instance) ConfirmReviewChat(data *api.ConfirmReviewChatRequest) (*api.ConfirmReviewChatResponse, error) {
	return instance.getApiInstance().ConfirmReviewChat(data)
}

// 用户禁言
func (instance *Instance) SilenceUser(data *api.SilenceUserRequest) (*api.SilenceUserResponse, error) {
	return instance.getApiInstance().SilenceUser(data)
}

// 获取禁言用户列表
func (instance *Instance) GetSilenceUserList(data *api.GetSilenceUserListRequest) (*api.GetSilenceUserListResponse, error) {
	return instance.getApiInstance().GetSilenceUserList(data)
}

// 修改主持人名称
func (instance *Instance) UpdatePresenterName(data *api.UpdatePresenterNameRequest) (*api.UpdatePresenterNameResponse, error) {
	return instance.getApiInstance().UpdatePresenterName(data)
}

// 修改弹幕开关
func (instance *Instance) UpdateBulletScreensSwitch(data *api.UpdateBulletScreensSwitchRequest) (*api.UpdateBulletScreensSwitchResponse, error) {
	return instance.getApiInstance().UpdateBulletScreensSwitch(data)
}

// 编辑轮播
func (instance *Instance) UpdateLoopVideo(data *api.UpdateLoopVideoRequest) (*api.UpdateLoopVideoResponse, error) {
	return instance.getApiInstance().UpdateLoopVideo(data)
}

// 开启、关闭轮播
func (instance *Instance) UpdateLoopVideoStatus(data *api.UpdateLoopVideoStatusRequest) (*api.UpdateLoopVideoStatusResponse, error) {
	return instance.getApiInstance().UpdateLoopVideoStatus(data)
}

// 修改直播间观看限制
func (instance *Instance) UpdateViewPermission(data *api.UpdateViewPermissionRequest) (*api.NoResultResponse, error) {
	return instance.getApiInstance().UpdateViewPermission(data)
}

// 修改直播间观看限制/评论限制自定义观看登录链接
func (instance *Instance) UpdateCustomizationViewPermission(data *api.UpdateCustomizationViewPermissionRequest) (*api.UpdateCustomizationViewPermissionResponse, error) {
	return instance.getApiInstance().UpdateCustomizationViewPermission(data)
}

// 获取拉流SDK初始化Token
func (instance *Instance) GetSDKToken(data *api.GetSDKTokenRequest) (*api.GetSDKTokenResponse, error) {
	return instance.getApiInstance().GetSDKToken(data)
}

// 获取STS2
func (instance *Instance) GetSTS() (*api.GetSTSResponse, error) {
	return instance.getApiInstance().GetSTS()
}
